interface SocialState {
  friends: Friend[];
  marketItems: MarketItem[];
  collaborativeFarms: CollaborativeFarm[];
  decorationRatings: DecorationRating[];
  dailyGifts: DailyGift[];
}

interface Friend {
  id: string;
  name: string;
  level: number;
  lastVisit: Date;
}

interface MarketItem {
  id: string;
  sellerId: string;
  itemType: string;
  price: number;
  quantity: number;
}

interface CollaborativeFarm {
  id: string;
  partners: string[];
  crops: any[];
  progress: number;
}

interface DecorationRating {
  farmId: string;
  rating: number;
  comments: string[];
}

interface DailyGift {
  id: string;
  fromId: string;
  toId: string;
  itemType: string;
  sentAt: Date;
}

export const social = {
  namespaced: true,
  
  state: (): SocialState => ({
    friends: [],
    marketItems: [],
    collaborativeFarms: [],
    decorationRatings: [],
    dailyGifts: []
  }),

  mutations: {
    addFriend(state, friend: Friend) {
      state.friends.push(friend);
    },
    
    addMarketItem(state, item: MarketItem) {
      state.marketItems.push(item);
    },
    
    updateCollaborativeFarm(state, farm: CollaborativeFarm) {
      const index = state.collaborativeFarms.findIndex(f => f.id === farm.id);
      if (index > -1) {
        state.collaborativeFarms[index] = farm;
      } else {
        state.collaborativeFarms.push(farm);
      }
    },
    
    addDecorationRating(state, rating: DecorationRating) {
      state.decorationRatings.push(rating);
    },
    
    addDailyGift(state, gift: DailyGift) {
      state.dailyGifts.push(gift);
    }
  },

  actions: {
    async visitFriend({ commit }, friendId: string) {
      // 实现访问好友农场的逻辑
    },
    
    async tradeCrop({ commit }, { itemId, quantity }) {
      // 实现农产品交易的逻辑
    },
    
    async startCollaboration({ commit }, partnerId: string) {
      // 实现开始合作种植的逻辑
    },
    
    async rateDecoration({ commit }, { farmId, rating, comment }) {
      // 实现装饰评分的逻辑
    },
    
    async sendDailyGift({ commit }, { toId, itemType }) {
      // 实现发送每日礼物的逻辑
    }
  },

  getters: {
    onlineFriends: (state) => {
      // 返回在线好友列表
      return state.friends.filter(friend => /* 在线判断逻辑 */);
    },
    
    availableMarketItems: (state) => {
      // 返回可购买的市场物品
      return state.marketItems.filter(item => item.quantity > 0);
    },
    
    activeCollaborations: (state) => {
      // 返回进行中的合作农场
      return state.collaborativeFarms.filter(farm => farm.progress < 100);
    }
  }
}; 